<table id="registers">
    <tr>
        <?php $fields_ids = array(); $i = 0; ?>
        <?php foreach ($fields as $field): ?>
            <th><?php echo $field->getTitle() ?></th>
            <?php $fields_ids[$i] = $field->getId(); $i++; ?>
        <?php endforeach; ?>
        <th>Fecha de creación</th>
    </tr>
    <?php foreach ($registers as $register): ?>
        <tr>
            <?php $values = $register->getValues(); ?>
            <?php if($values->count() == $fields->count()): ?>
                <?php foreach ($values as $value): ?>
                    <td><?php echo $value->getValue();?></td>
                <?php endforeach; ?>
            <?php else: ?>
                <?php $iter = new Doctrine_Collection_Iterator($values); $j = 0;?>
                <?php while ($iter->valid() && $j < $i): ?>
                    <?php $value = $iter->current(); ?>
                    <?php if($value->getFieldId() == $fields_ids[$j]): ?>
                        <td><?php echo $value->getValue() ?></td>
                        <?php $iter->next(); ?>
                    <?php else: ?>
                        <td>N/A</td>
                    <?php endif; ?>
                    <?php $j++; ?>
                <?php endwhile; ?>
            <?php endif; ?>
            <td><?php echo $register->getDateTimeObject('created_at')->format('d/m/Y - g:i a') ?></td>
        </tr>
    <?php endforeach; ?>
</table>
